package com.ayic.garbagerecycle.service.impl;

import com.ayic.garbagerecycle.mapper.WasteMapper;
import com.ayic.garbagerecycle.mapper.WasteTypeMapper;
import com.ayic.garbagerecycle.pojo.Result;
import com.ayic.garbagerecycle.pojo.WasteRecord;
import com.ayic.garbagerecycle.pojo.WasteType;
import com.ayic.garbagerecycle.service.WasteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WasteServiceImplement implements WasteService {

    @Autowired
    private WasteMapper wasteMapper;
    
    @Autowired
    private WasteTypeMapper wasteTypeMapper;
    //插入回收数据
    @Override
    public Result addRecord(WasteRecord wasteRecord, Integer userId) {
        wasteRecord.setCreatedAt(LocalDateTime.now());
        wasteRecord.setValue(1);
        wasteRecord.setUserId(userId);
        return Result.success("成功插入"+wasteMapper.addRecord(wasteRecord)+"条数据");
    }

    @Override
    public String queryType(Integer wasteType) {
        return wasteMapper.queryType(wasteType);
    }

    //根据站点ID获取对应站点的10条最近数据
    @Override
    public List<WasteRecord> getWasteRecordsByStationId(Integer stationId) {
        return wasteMapper.selectByStationId(stationId);
    }

    @Override
    public List<WasteRecord> queryWasteUserRec(Integer userId) {
        return wasteMapper.queryUserRec(userId);
    }

    @Override
    public WasteType getWasteTypeByName(String wasteTypeName) {
        return wasteTypeMapper.getWasteTypeByName(wasteTypeName);
    }
}